Skip to content

Fix/profile image duplicates#210

Open
Shubham15986 wants to merge 69 commits into
RECursion-NITD:testingfrom
Shubham15986:fix/profile-image-duplicates
Open

Fix/profile image duplicates#210
Shubham15986 wants to merge 69 commits into
RECursion-NITD:testingfrom
Shubham15986:fix/profile-image-duplicates

Conversation

@Shubham15986
Copy link
Copy Markdown

Fix: Prevent Duplicate Profile Images and Collision Suffix Files

Problem

The media directory contained over 4,700 files, including 2,200+ duplicate groups.
Duplicates were created due to Django appending suffixes (e.g., _w30EZ0i) when saving files with existing names.

Example:

  • images/username.png
  • images/username_w30EZ0i.png

Root Cause

  1. Signal Amplification
  • update_user_profile() was calling profile.save() on every User save
  • This triggered repeated image processing even when no new image was uploaded
  1. Non-idempotent Image Handling
  • Image processing ran on every save (including DB reloads)
  • Existing files were not deleted before saving → Django created suffixed duplicates
  • Old image files were not cleaned up

Changes Made

  1. Removed unnecessary signal-driven saves
  • Profile is now saved only when required (creation or explicit update)
  • Eliminates repeated image processing
  1. Implemented overwrite-safe image handling
  • Process images only for new uploads using _committed check
  • Delete existing file before saving to prevent suffix creation
  • Enforce deterministic file naming (images/username.png)
  • Always overwrite instead of creating new copies
  1. Added cleanup logic
  • Deletes previous image file when updated
  • Prevents orphaned files

Key Improvements

  • Idempotent save logic (no reprocessing on repeated saves)
  • No collision suffix files generated
  • Automatic cleanup of old images
  • Reduced unnecessary processing

Result

  • Duplicate image generation is prevented at the source
  • File naming is consistent and predictable
  • Storage remains clean (no accumulation of unused files)
  • Image handling is stable and efficient

Notes

  • Existing duplicate files are not modified in this PR
  • This fix ensures no new duplicates will be created going forward

Sivam2313 and others added 30 commits March 3, 2024 20:54
added views for profile roles and IE reviews
…ib-alumniAPI

created API to get alumni year wise
Blog and interview experience fixed by adding a new static image folder and a static image,
fixed email activation
login fixes, version changes and some other fixes
fixed team member icon hover and layout issue and some other change
Made a few backend changes to facilitate registration and user creation
… fixed email link using previous domain name, blocked the old UI
finalised certain login/signup flow APIs, fixed password reset issue, fixed email link using previous domain name, blocked the old UI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants